﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

///<summary>
///
///</summary>
public class GameState :State
{
    public override void ExecuteState(StateManager manager)
    {
        if (manager.IsSkipStartScnen)
        {
            ExitState(manager);
        }
        if (manager.IsSkipEndPanel)
        {
            ExitState(manager);
        }
    }
    public override void ExitState(StateManager manager)
    {
        if (manager.IsSkipStartScnen)
        {
            GameConfig.IsGameOver = true;
            AppFacde.Instance.RemoveMediator("GameMediator");
           
            SceneManager.sceneLoaded += OnSceneLoaded;
            SceneManager.LoadScene("Start");
            Debug.Log("转Start场景");
        }
        if (manager.IsSkipEndPanel)
        {
            AppFacde.Instance.RegisterCommand(GameEvents.END_COMMAND, typeof(EndCommand));
            StateManager.GetInstance.SetState(new EndState());
            
            SendNotification(GameEvents.END_COMMAND);
        }
    }
    public override void InitState(StateManager manager)
    {
        manager.IsSkipGameScnen = false;
    }
    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        SceneManager.sceneLoaded -= OnSceneLoaded;
        PlayerDataManager.GetIntance().Clear();
     
        StateManager.GetInstance.SetState(new StartState());
        SendNotification(GameEvents.START_COMMAND);
    }
}
